package com.jungle.client.dialog;



import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SampleDialog {

    public SampleDialog() {
        Dialog<ButtonType> dialog = new Dialog<>();
        dialog.setTitle("FromSampleDialog_title");
        dialog.setHeaderText("FromSampleDialog_header");
        dialog.setContentText("FromSampleDialog_content");
        dialog.getDialogPane().setContent(getContent());
        dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
        dialog.showAndWait().ifPresent(result -> log.info("Your choice: {}", result));
    }

    private GridPane getContent() {
        GridPane gridPane = new GridPane();

        gridPane.lookup("dialog-pane");
        gridPane.setHgap(10);
        gridPane.setVgap(10);
        int rowIndex = 0;
        ChoiceBox<String> choiceBox = new ChoiceBox<>();
        choiceBox.getItems().addAll("FromSampleDialog_choiceBox_item1", "FromSampleDialog_choiceBox_item2", "FromSampleDialog_choiceBox_item3");
        choiceBox.setValue("FromSampleDialog_choiceBox_item1");
        gridPane.add(new Label("ChoiceBox"), 0, rowIndex);
        gridPane.add(choiceBox, 1, rowIndex);

        rowIndex++;
        ComboBox<String> comboBox = new ComboBox<>();
        comboBox.getItems().addAll("FromSampleDialog_comboBox_item1", "FromSampleDialog_comboBox_item2", "FromSampleDialog_comboBox_item3");
        comboBox.setValue("FromSampleDialog_comboBox_item1");
        gridPane.add(new Label("ComboBox"), 0, rowIndex);
        gridPane.add(comboBox, 1, rowIndex);

        rowIndex++;
        TextArea textArea = new TextArea();
        textArea.setText("FromSampleDialog_textArea");
        gridPane.add(new Label("TextArea"), 0, rowIndex);
        gridPane.add(textArea, 1, rowIndex);

        rowIndex++;
        PasswordField passwordField = new PasswordField();
        gridPane.add(new Label("PasswordField"), 0, rowIndex);
        gridPane.add(passwordField, 1, rowIndex);

        rowIndex++;
        TextField textField = new TextField();
        textField.setText("FromSampleDialog_textField");
        gridPane.add(new Label("TextField"), 0, rowIndex);
        gridPane.add(textField, 1, rowIndex);

        rowIndex++;
        DatePicker datePicker = new DatePicker();
        datePicker.setShowWeekNumbers(true);
        datePicker.setValue(java.time.LocalDate.now());

        gridPane.add(new Label("DatePicker"), 0, rowIndex);
        gridPane.add(datePicker, 1, rowIndex);

        rowIndex++;
        ColorPicker colorPicker = new ColorPicker();
        gridPane.add(new Label("ColorPicker"), 0, rowIndex);
        gridPane.add(colorPicker, 1, rowIndex);

        rowIndex++;
        CheckBox checkBox = new CheckBox("客户");
        CheckBox checkBox2 = new CheckBox("供应商");
        CheckBox checkBox3 = new CheckBox("项目");
        gridPane.add(new Label("CheckBox"), 0, rowIndex);
        HBox hBox = new HBox();
        hBox.setSpacing(10);
        hBox.getChildren().addAll(checkBox, checkBox2, checkBox3);
        gridPane.add(hBox, 1, rowIndex);

        rowIndex++;
        RadioButton radioButton = new RadioButton("材料");
        RadioButton radioButton1 = new RadioButton("钢板");
        RadioButton radioButton2 = new RadioButton("油漆");
        ToggleGroup toggleGroup0 = new ToggleGroup();
        radioButton.setToggleGroup(toggleGroup0);
        radioButton1.setToggleGroup(toggleGroup0);
        radioButton2.setToggleGroup(toggleGroup0);
        gridPane.add(new Label("RadioButton"), 0, rowIndex);
        HBox hBox2 = new HBox();
        hBox2.getChildren().addAll(radioButton, radioButton1, radioButton2);
        hBox2.setSpacing(10);

        gridPane.add(hBox2, 1, rowIndex);

        rowIndex++;
        ToggleButton toggleButton = new ToggleButton("合同");
        ToggleButton toggleButton2 = new ToggleButton("费用");
        ToggleButton toggleButton3 = new ToggleButton("预算");
        ToggleGroup toggleGroup = new ToggleGroup();
        toggleButton.setToggleGroup(toggleGroup);
        toggleButton2.setToggleGroup(toggleGroup);
        toggleButton3.setToggleGroup(toggleGroup);
        gridPane.add(new Label("ToggleButton"), 0, rowIndex);
        HBox hBox1 = new HBox();
        hBox1.getChildren().addAll(toggleButton, toggleButton2, toggleButton3);
        gridPane.add(hBox1, 1, rowIndex);

        rowIndex++;
        Slider slider = new Slider();
        slider.setMin(0);
        slider.setMax(100);
        slider.setValue(50);
        gridPane.add(new Label("Slider"), 0, rowIndex);
        gridPane.add(slider, 1, rowIndex);

        rowIndex++;
        Spinner<Integer> spinner = new Spinner<>();
        SpinnerValueFactory.IntegerSpinnerValueFactory valueFactory = new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 100, 50);
        spinner.setValueFactory(valueFactory);
        gridPane.add(new Label("Spinner"), 0, rowIndex);
        gridPane.add(spinner, 1, rowIndex);

        slider.valueProperty().addListener((observable, oldValue, newValue) -> {
            log.info("Slider value: {}", newValue);
                valueFactory.setValue(((Double) newValue).intValue());
        });
        valueFactory.valueProperty().addListener((observable, oldValue, newValue) -> {
            log.info("Spinner value: {}", newValue);
            slider.setValue(newValue);
        });


        //ListView<String> listView = new ListView<>();
        //TableView<String> tableView = new TableView<>();


        return gridPane;
    }

}
